import { IPSWFInteractiveLink } from './ipswfinteractive-link';
import { IPSWFInteractiveProcess } from './ipswfinteractive-process';
import { IPSWFLinkRole } from './ipswflink-role';
import { IPSWFVersion } from './ipswfversion';
import { PSWFLinkImpl } from './pswflink-impl';

export class PSWFInteractiveLinkImpl extends PSWFLinkImpl implements IPSWFInteractiveLink {
  get formCodeName(): string {
    return this.M.formCodeName;
  }

  protected frompswfprocess: IPSWFInteractiveProcess | null = null;

  getFromPSWFProcess(): IPSWFInteractiveProcess | null {
    if (this.frompswfprocess != null) return this.frompswfprocess;
    const value = this.M.getFromPSWFProcess;
    if (value == null) {
      return null;
    }
    const ipswfversion = this.getParentPSModelObject('wf.IPSWFVersion') as IPSWFVersion;
    if (ipswfversion != null) {
      this.frompswfprocess = ipswfversion.findPSWFProcess(value) as IPSWFInteractiveProcess;
    }
    return this.frompswfprocess;
  }

  get fromPSWFProcess(): IPSWFInteractiveProcess | null {
    return this.getFromPSWFProcess();
  }

  getFromPSWFProcessMust(): IPSWFInteractiveProcess {
    const value = this.getFromPSWFProcess();
    if (value == null) {
      throw new Error('未指定源流程处理');
    }
    return value;
  }

  get mobFormCodeName(): string {
    return this.M.mobFormCodeName;
  }

  get mobViewCodeName(): string {
    return this.M.mobViewCodeName;
  }

  get nextCondition(): string {
    return this.M.nextCondition;
  }

  protected pswflinkroles: IPSWFLinkRole[] | null = null;

  getPSWFLinkRoles(): IPSWFLinkRole[] | null {
    if (this.pswflinkroles == null) {
      this.pswflinkroles = this.fillChildListModel(this.M.getPSWFLinkRoles, 'wf.IPSWFLinkRole') as IPSWFLinkRole[];
    }
    return this.pswflinkroles;
  }

  get psWFLinkRoles(): IPSWFLinkRole[] | null {
    return this.getPSWFLinkRoles();
  }

  findPSWFLinkRole(objKey: any): IPSWFLinkRole | null {
    return this.getPSModel5('wf.IPSWFLinkRole', this.getPSWFLinkRoles(), objKey) as IPSWFLinkRole;
  }

  get viewCodeName(): string {
    return this.M.viewCodeName;
  }

  get cls(): string {
    return 'PSWFInteractiveLinkImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'wf.IPSWFInteractiveLink') return true;
    return super.instanceof(cls);
  }
}
